//
//  ViewController.swift
//  sizeToFitDemo
//
//  Created by 李煜 on 2021/8/19.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = .white
        

        let contentView = UIView(frame: .init(x: 10, y: 50, width: 0, height: 0))
        contentView.backgroundColor = .gray
        view.addSubview(contentView)

        let subView = UIView(frame: CGRect.init(x: 0, y: 0, width: 80, height: 80))
        subView.backgroundColor = .cyan
        contentView.addSubview(subView)
        contentView.sizeToFit()

        let label = UILabel(frame: CGRect(x: 10, y: 20, width: 0, height: 0))
        label.text = "hello swift"
        label.backgroundColor = .systemPink
        label.sizeToFit()
        view.addSubview(label)
        print(contentView.frame,label.frame)
        
        
        //imgView
        let img = UIImage(named: "account")
//        let img = UIImage(systemName: "pencil")

        let imgV = UIImageView(frame: .zero);
        imgV.image = img
        imgV.sizeToFit()
        
        let left = UIView(frame: .zero)
        left.addSubview(imgV)
        
        let tf = UITextField(frame: CGRect(x: 100, y: 300, width: 300, height: 50))
        tf.borderStyle = .roundedRect
        tf.leftView = left;
        tf.leftViewMode = .always
        tf.contentVerticalAlignment = .center
        view.addSubview(tf)
//        view.addSubview(imgV)
        
    }


}

